package com.info.provider.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
 * Created by pengshuo on 2018/2/1 16:55
 * Description: Base64 互转
 * Modified By:
 * Version:
 *
 * @author pengshuo
 */
public class Base64Util {

    private final static BASE64Encoder encoder = new BASE64Encoder();
    private final static BASE64Decoder decoder = new BASE64Decoder();

    /**
     * byte[] to Base64 String
     * @param bytes
     * @return
     */
    public static String arrayBufferToBase64(byte[] bytes) throws IOException{
        return encoder.encode(bytes);
    }

    /**
     * base64 String to byte[]
     * @param base64
     * @return
     */
    public static byte[] base64ToArrayBuffer(String base64) throws IOException{
        return decoder.decodeBuffer(base64);
    }

}
